package org.footballmanager.pandafootball.system.form.impl;

import lombok.Getter;
import lombok.Setter;
import org.footballmanager.pandafootball.common.constants.Constants;
import org.footballmanager.pandafootball.system.domain.FootPerson;
import org.footballmanager.pandafootball.system.form.SearchForm;
import org.springframework.util.StringUtils;
import tk.mybatis.mapper.entity.Example;

import java.io.Serializable;
import java.util.Date;

@Setter
@Getter
public class FootPersonSearchForm extends SearchForm implements Serializable {
    private static final long serialVersionUID = 8090668615941861534L;
    protected String name;
    protected Long gj;
    protected Long djId;
    protected Long wz;
    protected String nlName1;
    protected Integer nlValueStart1 = 0;
    protected Integer nlValueEnd1 = 0;
    protected String nlName2;
    protected Integer nlValueStart2 = 0;
    protected Integer nlValueEnd2 = 0;
    protected String nlName3;
    protected Integer nlValueStart3 = 0;
    protected Integer nlValueEnd3 = 0;
    protected String nlName4;
    protected Integer nlValueStart4 = 0;
    protected Integer nlValueEnd4 = 0;
    protected Date updateDate;

    public Example buildSearchCommond() {
        Example example = new Example(FootPerson.class);
        Example.Criteria criteria = example.createCriteria();
        processName(criteria, example);
        if (gj != null) {
            criteria.andEqualTo("gj", gj);
        }
        if (djId != null) {
            criteria.andEqualTo("djId", djId);
        }
        if (wz != null) {
            criteria.andEqualTo("wz", wz);
        }
        criteria.andEqualTo("delFlag", 0);
        example.orderBy("createTime").desc();
        return example;
    }

    private void processName(Example.Criteria criteria, Example example) {
        if (!StringUtils.isEmpty(this.name)) {
            criteria.andLike("name", "%" + this.name.trim() + "%");
            Example.Criteria criteria2 = example.createCriteria();
            criteria2.andLike("yw", "%" + this.name.trim() + "%");
            Example.Criteria criteria3 = example.createCriteria();
            criteria3.andEqualTo(Constants.ID, this.name.trim());
            example.or(criteria2);
            example.or(criteria3);
        }
    }
}
